﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using ERCS.Model;
using Microsoft.EntityFrameworkCore;
using ERCS.ViewModel.BasicData.CityVMs;

namespace ERCS.ViewModel.BasicData.HospitalVMs
{
    public partial class HospitalVM : BaseCRUDVM<Hospital>
    {
        //public List<ComboSelectListItem> AllLocations { get; set; }
        public CityListVM Cities { get; set; }

        public HospitalVM()
        {
            SetInclude(x => x.Location);
        }

        public override void Validate()
        {
            //var patientCount = DC.Set<Patient>().AsNoTracking().Where(x => x.LocationId == Entity.LocationId).Count();
            //if(patientCount < 10)
            //{
            //    MSD.AddModelError("Entity.LocationId", "所选地区没有病人");
            //}
            base.Validate();
        }


        protected override void InitVM()
        {
            //AllLocations = DC.Set<City>().GetSelectListItems(LoginUserInfo?.DataPrivileges, null, y => y.Name);
            Cities = new CityListVM();
            Cities.CopyContext(this);
        }

        protected override void ReInitVM()
        {
            base.ReInitVM();
        }

        protected override Hospital GetById(object Id)
        {
            return base.GetById(Id);
        }

        public override DuplicatedInfo<Hospital> SetDuplicatedCheck()
        {
            var rv = CreateFieldsInfo(SimpleField(x => x.Name));

            return rv;
        }


        public override Task DoAddAsync()
        {
            return base.DoAddAsync();
        }

        public override void DoAdd()
        {           
            base.DoAdd();
        }

        public override Task DoEditAsync(bool updateAllFields = false)
        {
            return base.DoEditAsync(updateAllFields);
        }
        public override void DoEdit(bool updateAllFields = false)
        {
            base.DoEdit(updateAllFields);
        }


        public override Task DoDeleteAsync()
        {
            return base.DoDeleteAsync();
        }
        public override void DoDelete()
        {
            base.DoDelete();
        }

        public override Task DoRealDeleteAsync()
        {
            return base.DoRealDeleteAsync();
        }

        public override void DoRealDelete()
        {
            base.DoRealDelete();
        }
    }
}
